import { _decorator, Component, EditBox, game, Game, Label, Layout, Node, ScrollView, Slider, Sprite, Toggle, Vec2, Vec3 } from 'cc';
import { UIManager } from '../UIManager';
import { LanauageManager } from '../LanauageManager';
import { GameData, videoCfg } from '../GameData';
import { HttpClient } from '../net/HttpClient';
import { EventManager } from '../EventManager';
import { AudioMgr } from '../AudioMgr';
import { Util } from '../Util';
const { ccclass, property } = _decorator;

@ccclass('popupAnswer2')
export class popupAnswer2 extends Component {

    @property(Label)
    desLab:Label = null;

    @property(Node)
    content:Node = null;

    onEnable() {
        this.refresh();
    }

    refresh(){

        if (!GameData.curVideoCfg){
            return;
        }
        this.desLab.string = GameData.curVideoCfg.problem;

        for (let index = 0; index < this.content.children.length; index++) {
            const element = this.content.children[index];
            element.active = false;
        }

        for (let index = 0; index < this.content.children.length; index++) {
            const element = this.content.children[index];
            if (GameData.curVideoCfg.answer[index]){
                element.active = true;
                element.getChildByName("Label").getComponent(Label).string = (index==0?"A":index==1?"B":"C") + ": "  + GameData.curVideoCfg.answer[index];
            }
        }
    }

    onClickHandler(event:Event, str:string){
        let isRight:boolean = false;
        if (GameData.curVideoCfg.right.indexOf(0)>= 0 && str == "btn1"){
            isRight = true;
        }
        else if (GameData.curVideoCfg.right.indexOf(1)>= 0 && str == "btn2"){
            isRight = true;
        }
        else if (GameData.curVideoCfg.right.indexOf(2)>= 0 && str == "btn3"){
            isRight = true;
        }

        if (isRight){
            this.closeView();
            EventManager.eventTarget.emit(EventManager.PLAY_VIDEO);
        }else{
            UIManager.open(UIManager.uiNamePath.popupResult);
        }
    }

    closeView(){
        UIManager.close(this.node);
    }
}

